﻿448.找到所有数组中消失的数字
/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
int* findDisappearedNumbers(int* nums, int numsSize, int* returnSize) {
    int* ans = (int*)malloc(sizeof(int) * numsSize);
    *returnSize = 0;

    int* arr = (int*)calloc(sizeof(int), numsSize);
    for (int i = 0; i < numsSize; i++)
    {
        arr[nums[i] - 1]++;
    }
    for (int i = 0; i < numsSize; i++)
    {
        if (arr[i] == 0)
        {
            ans[(*returnSize)++] = i + 1;
        }
    }
    return ans;
}

459.重复的子字符串
bool repeatedSubstringPattern(char* s) {
    int len = strlen(s);
    for (int i = 1; i <= len / 2; i++)
    {
        if (len % i == 0)
        {
            int flag = 1;
            for (int j = i; j < len; j++)
            {
                if (s[j] != s[j - i])
                {
                    flag = 0;
                    break;
                }
            }
            if (flag == 1)
            {
                return true;
            }
        }
    }
    return false;
}

476.数字的补数
int findComplement(int num) {
    int ans = 0, pos = 0;
    for (int i = 31; i >= 0; i--)
    {
        if (((num >> i) & 1) == 1)
        {
            pos = i;
            break;
        }
    }
    for (int i = 0; i <= pos; i++)
    {
        if (((num >> i) & 1) == 1)
        {
            ans += 0;
        }
        else
        {
            ans += pow(2, i);
        }
    }
    return ans;
}

482.密钥格式化
char* licenseKeyFormatting(char* s, int k) {
    char* ans = (char*)malloc(sizeof(char) * (strlen(s) * 2));
    char* temp = (char*)malloc(sizeof(char) * (strlen(s) + 1));
    int n = 0, m = 0, flag = 0;

    for (int i = 0; i < strlen(s); i++)
    {
        if (s[i] == '-')
        {
            flag = 1;
            continue;
        }
        else if (s[i] >= 'a' && s[i] <= 'z')
        {
            temp[n++] = s[i] - 32;
        }
        else
        {
            temp[n++] = s[i];
        }
    }
    temp[n] = '\0';

    for (int i = 0; i < strlen(temp) % k; i++)
    {
        ans[m++] = temp[i];
    }
    for (int i = strlen(temp) % k; i < strlen(temp); i++)
    {
        if ((i - strlen(temp) % k) % k == 0 && i != 0)
        {
            ans[m++] = '-';
            ans[m++] = temp[i];
        }
        else
        {
            ans[m++] = temp[i];
        }
    }
    ans[m] = '\0';
    return ans;
}

3115.质数的最大距离
int Prime(int n) {
    if (n == 1)
    {
        return 0;
    }
    int flag = 1;
    for (int i = 2; i < n; i++)
    {
        if (n % i == 0)
        {
            flag = 0;
            break;
        }
    }
    return flag;
}

int maximumPrimeDifference(int* nums, int numsSize) {
    int pos1 = 0, pos2 = 0;
    for (int i = 0; i < numsSize; i++)
    {
        if (Prime(nums[i]))
        {
            pos1 = i;
            break;
        }
    }

    for (int i = numsSize - 1; i >= 0; i--)
    {
        if (Prime(nums[i]))
        {
            pos2 = i;
            break;
        }
    }
    return pos2 - pos1;
}